package com.qijian.maindata.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.maindata.domain.CheckHistory;
import com.qijian.maindata.domain.ProcessOrder;
import com.qijian.maindata.domain.Project;
import com.qijian.maindata.domain.dto.WorkloadDTO;
import com.qijian.maindata.domain.query.ProcessOrderDelayQuery;
import com.qijian.maindata.domain.query.ProcessOrderQuery;
import com.qijian.maindata.domain.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * 工序工单Mapper接口
 *
 * @author qijian
 * @date 2021-10-09
 */
public interface ProcessOrderMapper extends BaseMapper<ProcessOrder> {

    @Select("select count(*) from main_process_order WHERE ${ew.sqlSegment} ")
    long countByPlanSystem(@Param(Constants.WRAPPER) Wrapper<ProcessOrderQuery> queryWrapper);

    @Select("select count(1) from main_process_order WHERE create_time >= CURRENT_DATE ")
    long countCurrentDateWithDel();

    long countByWorkIds(@Param("ids") Set<Long> workIds);

    Page<ProcessOrderVo> selectWorkId(Page<ProcessOrder> page, @Param(Constants.WRAPPER) Wrapper<ProcessOrderQuery> queryWrapper);

    Page<ProcessOrderVo> selectVo(Page<ProcessOrder> page, @Param(Constants.WRAPPER) Wrapper<ProcessOrderQuery> queryWrapper);

    Page<ProcessOrderVo> listHistory(Page<ProcessOrder> page, @Param(Constants.WRAPPER) Wrapper<ProcessOrderQuery> queryWrapper);

    Page<ProcessOrderNewVo> selectByCondition(Page<ProcessOrder> page, @Param("param") ProcessOrderQuery queryWrapper);

    Page<ProcessOrderVo> selectProcessTypeVo(Page<ProcessOrder> page, @Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    Page<ProcessOrderGroupVo> selectGroupVo(Page<ProcessOrder> page, @Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    List<ProcessOrderGroupVo> selectGroupListVo(@Param("current") long current, @Param("size") long size, @Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    List<ProcessOrderGroupVo> selectGroupVo(@Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    List<ProcessOrderDetailVo> selectProcessAndDetailVo(@Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    void updateCheckWuStatus(@Param("ids") Set<Long> wuId, @Param("userId") Long userId, @Param("updateBy") String updateBy, @Param("status") Integer status);

    List<ProjectProcessVo> selectProcessVo(@Param("projectId") Long projectId, @Param("type") String type, @Param("deptId") Long deptId);

    List<ProcessOrder> checkWork(@Param("ids") Set<Long> ids);

    List<ProcessOrder> projectOrderAllFinished(@Param("ids") Set<Long> ids);

    List<ProcessOrder> groupByDelay(@Param("projectId") Long projectId, @Param("level") Integer level);

    Long processFinishCount(@Param("projectId") Long projectId, @Param("processIds") List<Long> processIds);

    List<ProcessOrderSumVo> sumByFactory(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    List<ProjectProcessVo> selectQualityVo(@Param("projectId") Long projectId);

    Integer countByOutIdAndWorkId(@Param("outId") Long outId, @Param("workId") Long workId);

    Page<ProcessOrderVo> selectProcessOrderByProjectUserId(Page<ProcessOrder> page, @Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    WorkloadDTO selectTotalCost(@Param(Constants.WRAPPER) QueryWrapper<ProcessOrderQuery> queryWrapper);

    List<ProcessOrder4BudgetVo> list4NewBudget(@Param("costFactory") String costFactory, @Param("projectId") Long projectId);

    Page<ProcessOrderNewVo> getList4BudgetDetail(Page<ProcessOrder> page, @Param("param") ProcessOrderQuery queryWrapper);

    //获取xls数据，去掉工序的查询条件
    List<ProcessOrderNewExcelVo> getList4BudgetDetailXls(@Param("param") ProcessOrderQuery queryWrapper);

    Page<ProcessOrderVo> selectDelayVo(Page<ProcessOrder> page, @Param(Constants.WRAPPER) Wrapper<ProcessOrderDelayQuery> queryWrapper);

    int checkProcessOrderDelay(@Param("wuIds") Set<Long> wuId);

    List<ProcessOrderRateVo> listProductRateProcessOrder(@Param("projectId") Long projectId);

    List<ProcessOrderRateDetailVo> listProductRateProcessOrderDetail(@Param("projectId") Long projectId,
                                                                     @Param("factoryName") String factoryName,
                                                                     @Param("processTypeName") String processTypeName,
                                                                     @Param("isOut") Boolean isOut);


    List<ProcessOrderRateCategoryVo> listProductRateProcessOrderCategory(@Param("projectId") Long projectId,
                                                                         @Param("factoryName") String factoryName,
                                                                         @Param("isOut") Boolean isOut);

    Boolean updateProcessOrderStatusOutIn(@Param(value = "workIds") List<Long> workIds);

    Page<ProcessOrderNewVo> list4CostReport(Page<ProcessOrder> page, @Param("param") ProcessOrderQuery queryWrapper);

    List<ProcessOrder> check4ProductionAndDelivery(@Param("ids") Set<Long> ids, @Param("packing") String packing, @Param("delivering") String delivering);

    List<ProcessOrderInfoVo> selectOrderPricesSum(@Param("param") ProcessOrderQuery queryWrapper);

    List<ProcessOrderInfoVo> selectOrderPricesSumTemp(@Param("param") ProcessOrderQuery queryWrapper);

    List<ProcessOrderInfoVo> selectManagerPrice(@Param("param") ProcessOrderQuery queryWrapper);

    List<ProcessOrderInfoVo> selectManagerPriceTemp(@Param("param") ProcessOrderQuery queryWrapper);

    Page<ProcessOrderInfoVo> getProjectDeptLevelDetails(Page<ProcessOrder> page, @Param("param") ProcessOrderQuery queryWrapper);

    Page<ProcessOrderRateDetailVo> list4WorkShopDetails(Page page, @Param("param") ProcessOrderQuery queryWrapper);

    Page<ProcessOrderDetail4projectPerformanceVo> list4WorkShopDetailsNew(Page page, @Param("param") ProcessOrderQuery queryWrapper);


    Page<ProcessOrderRateDetailVo> list4ProjectDetails(Page page, @Param("param") ProcessOrderQuery queryWrapper);
    Page<ProcessOrderDetail4projectPerformanceVo> list4ProjectDetailsNew(Page page, @Param("param") ProcessOrderQuery queryWrapper);



    Page<ProcessOrderInfoVo> selectNcrList(Page<ProcessOrder> page, @Param("param") ProcessOrderQuery queryWrapper, @Param("type") String type);

    /**
     * 合并派工获取开工令
     *
     * @param queryWrapper
     * @return
     */

    List<Project> getProject(@Param("param") ProcessOrderQuery queryWrapper);

    /**
     * 合并派工获取工序
     *
     * @param queryWrapper
     * @return
     */

    List<ProcessOrder> getProcess(@Param("param") ProcessOrderQuery queryWrapper);

    List<CheckHistory> listCheckHistory();

    List<ProcessOrderRemindVo> list4RemindUnReceive(@Param("startTime") String startTime, @Param("gapHours") Long gapHours, @Param("warningHours") Long warningHours);

    List<ProcessOrderRemindVo> list4RemindUnCheck(@Param("startTime") String startTime, @Param("gapHours") Long gapHours, @Param("warningHours") Long warningHours);

    List<ProcessOrderRemindVo> list4RemindUnReport(@Param("startTime") String startTime, @Param("gapHours") Long gapHours, @Param("warningHours") Long warningHours);
}
